<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
</head>

<body>
    <script>
        // chunk 数组切割
        let arr = [1, 2, 3, 4, 5, 6, 7, 8];
        let newArr = _.chunk(arr, 3);
        console.log(newArr);

        // compact 数组去空值， 所有的空值， 0， NaN过滤掉
        let arr1 = [1, 2, NaN, undefined, '', 0];
        let newArr1 = _.compact(arr1);
        console.log(newArr1);

        // uniq 数组去重
        let arr2 = [1, 2, 1, 2, 3, 4];
        let newArr2 = _.uniq(arr2);
        console.log(newArr2);

        //  reject 根据条件删除元素
        let arr3 = [{
                id: 0,
                name: 'tom',
                age: 23
            },
            {
                id: 1,
                name: 'tom1',
                age: 30
            }
        ];
        let newArr3 = _.reject(arr3, ['id', 0]);
        console.log(newArr3);

        //_.get方法
        let object = {
            'a': [{
                'b': [{
                    'c': 3
                }]
            }]
        };

        let num = _.get(object, 'a[0].b[0].c'); // 可以传三个参数(对象,路径，默认值)
        console.log(num)
    </script>
</body>

</html>